package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @description 供应商管理Controller层
 */
@RestController
@RequestMapping("/supplier")
public class SupplierManageController {

    @Autowired
    SupplierManageService supplierManageService;

    /*
    * 请求URL：http://localhost:8080/supplier/list
        请求参数：Integer page（当前页数）, Integer rows（每页显示的记录数）, String supplierName
        请求方式：POST
        返回值类型： JSON
        返回值：Map<String,Object>
    * */
    @PostMapping("/list")
    @ResponseBody
    public Map<String,Object> pageSupplierList(
            @RequestParam(value = "page") Integer page ,
            @RequestParam(value = "rows") Integer rows ,
            @RequestParam(value = "supplierName" , required = false) String supplierName){
        Map<String, Object> map = supplierManageService.pageSupplierList((page - 1) * rows, rows, supplierName);

        return map;
    }

    /*添加或修改供应商
    请求URL：http://localhost:8080/supplier/save?supplierId=1
        请求参数：Supplier supplier
        请求方式：POST
        返回值类型： JSON
        返回值：ServiceVO
    */
    @PostMapping("/save")
    @ResponseBody
    public ServiceVO addSupplier(Supplier supplier){
        return supplierManageService.save(supplier);
    }

    /*删除供应商
        请求URL：http://localhost:8080/supplier/delete
        请求参数：String  ids
        请求方式：POST
        返回值类型：JSON
        返回值：ServiceVO
        */
    @PostMapping("/delete")
    @ResponseBody
    public ServiceVO deleteSupplier(String ids){
        return supplierManageService.deleteSupplier(ids);
    }
}
